package com.ysy.tz.core.selfcomp;

import com.ysy.tz.core.engine.CustomerMethodEventHandler;
import com.ysy.tz.core.skin.CustomerPaginationSkin;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.scene.control.Pagination;
import javafx.scene.control.Skin;

public class CustomerPagination extends Pagination {
    private IntegerProperty pageSize;
    private IntegerProperty currentStartRow;
    private IntegerProperty currentEndRow;
    private IntegerProperty totalRow;
    private IntegerProperty totalPages;
    private CustomerMethodEventHandler onPageSizeChanged;
    private CustomerPaginationSkin skin;

    public CustomerPagination(int pageCount, int pageIndex) {
        super(pageCount, pageIndex);
        this.pageSize = new SimpleIntegerProperty(this, "pageSize", 20);
        this.currentStartRow = new SimpleIntegerProperty(this, "currentStartRow", 0);
        this.currentEndRow = new SimpleIntegerProperty(this, "currentEndRow", 0);
        this.totalRow = new SimpleIntegerProperty(this, "totalRow", 0);
        this.totalPages = new SimpleIntegerProperty(this, "totalPages", 1);
        this.pageCountProperty().bind(this.totalPages);
        this.setMaxPageIndicatorCount(10);
        this.setStyle("-fx-font-size: 20;-fx-page-information-visible:false;");
        this.pageSize.addListener(new ChangeListener<Number>() {
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                CustomerPagination.this.onPageSizeChanged.handle((Event)null);
            }
        });
        this.currentPageIndexProperty().addListener(new ChangeListener<Number>() {
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                CustomerPagination.this.onPageSizeChanged.handle((Event)null);
            }
        });
    }

    public CustomerPagination(int pageCount) {
        this(pageCount, 0);
    }

    public CustomerPagination() {
        this(1, 0);
    }

    public final void setOnPageSizeChanged(CustomerMethodEventHandler<? super Event> value) {
        this.onPageSizeChanged = value;
    }

    public final CustomerMethodEventHandler<? super Event> getOnPageSizeChanged() {
        return this.onPageSizeChanged;
    }

    protected Skin<?> createDefaultSkin() {
        this.skin = new CustomerPaginationSkin(this);
        return this.skin;
    }

    public final void setPageSize(int value) {
        this.pageSize.set(value);
    }

    public final int getPageSize() {
        return this.pageSize.get();
    }

    public int getCurrentStartRow() {
        return this.currentStartRow.get();
    }

    public IntegerProperty currentStartRowProperty() {
        return this.currentStartRow;
    }

    public void setCurrentStartRow(int currentStartRow) {
        this.currentStartRow.set(currentStartRow);
    }

    public int getCurrentEndRow() {
        return this.currentEndRow.get();
    }

    public IntegerProperty currentEndRowProperty() {
        return this.currentEndRow;
    }

    public void setCurrentEndRow(int currentEndRow) {
        this.currentEndRow.set(currentEndRow);
    }

    public int getTotalRow() {
        return this.totalRow.get();
    }

    public IntegerProperty totalRowProperty() {
        return this.totalRow;
    }

    public void setTotalRow(int totalRow) {
        this.totalRow.set(totalRow);
    }

    public void setTotalPages(int totalPages) {
        this.totalPages.set(totalPages);
    }

    public void refreshDisplaySkin() {
        this.skin.refresh();
    }
}
